<template>
  <node-template @updateData="updateParentData" :uid="_uid" store-data-key="approverConfigData"
    place-holder-method-name="setApproverStr" check-method-name="checkApproval" @open="open"
    :node-config="nodeConfig"></node-template>
</template>

<script setup lang="ts">
// TODO: 表单模版节点-审批节点
import { getCurrentInstance, computed, onMounted, ref, watch } from "vue";
import { useFlowStore } from '../../../stores/flow'
import { useStore } from "../../../stores";
import NodeTemplate from "./node-template.vue";

let flowStore = useFlowStore();
let emits = defineEmits(['updateData']);
let store = useStore();
let { setApprover, setApproverConfig, } = store;
let _uid = getCurrentInstance().uid;
let props = defineProps({
  nodeConfig: {
    type: Object, default: () => {
    }
  }
});

const step2FormList = computed(() => {
  let step2 = flowStore.step2;
  return step2;
})

watch(() => step2FormList.value, (val) => {
  let nodeConfig = props.nodeConfig;
  if (nodeConfig.type == 1) {
    //审批人
    if (nodeConfig.assignedType == 8) {
      //表单人员
      let formUserId = nodeConfig.formUserId;
      let length = val.filter(res => res.id === formUserId).length;
      if (length == 0) {
        nodeConfig.formUserId = ''
        nodeConfig.formUserName = ''
        nodeConfig.error = true;
        nodeConfig.errorMsg = '请选择表单人员';
      }
    }
  }
})

const updateParentData = (d) => {
  emits("updateData", d);
}

// 点击审批节点事件
function open() {
  // 设定审批人
  setApprover(true);
  // 设定审批人设置参数
  setApproverConfig({
    value: JSON.parse(JSON.stringify(props.nodeConfig)),
    flag: false,
    id: _uid,
  });
}
</script>

<style scoped lang="less"></style>
